package com.bdc.user.dao.impl;

import com.bdc.user.dao.IUserDao;
import com.bdc.user.domain.UserInfo;
import com.google.inject.Inject;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * User: shawn
 * Date: 2011-6-20
 * Time: 20:54:13
 */
public class IUserDaoImpl implements IUserDao {

    @Inject
    private EntityManager em;

    public void addUser(UserInfo info) {
        em.persist(info);
    }

    public UserInfo getUserInfo(String mail) {
        Query query = em.createNativeQuery("SELECT * FROM user WHERE mail=?", UserInfo.class);
        query.setParameter(1, mail);
        List<UserInfo> list = query.getResultList();
        return list.size() == 0 ? null : list.get(0);
    }
}
